package com.wangrui.service.impl;

import com.wangrui.utils.Page;
import com.wangrui.dto.StudentInfo;
import com.wangrui.pojo.Student;
import com.wangrui.mapper.StudentMapper;
import com.wangrui.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王锐
 * @since 2020-07-10
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public Map<String, Object> AllStudents(Page<StudentInfo> page1) {
        List<StudentInfo> allStudentInfo = studentMapper.getAllStudentInfo(page1);
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",studentMapper.selectCount(null));
        map.put("rows",allStudentInfo);
        return map;
    }

    @Override
    public int studentDelete(int ids) {
        return studentMapper.deleteById(ids);
    }

    @Override
    public int studentSave(Student student) {
        return studentMapper.insert(student);
    }

    @Override
    public int studentUpdate(Student student) {
        return studentMapper.updateById(student);
    }
}
